package service

import (
	"context"
	"jk-time/webook/feed/domain"
	"jk-time/webook/feed/repository"
	"time"
)

const (
	LikeEventName = "like_event"
)

type LikeEventService struct {
	repo repository.FeedRepository
}

func NewLikeEventService(repo repository.FeedRepository) Handler {
	return &LikeEventService{repo: repo}
}

func (f LikeEventService) CreateHandleEvent(ctx context.Context, ext domain.ExtendFields) error {
	liked, err := ext.Get("liked").AsInt64()
	if err != nil {
		return err
	}
	return f.repo.CreatePushEvents(ctx, []domain.FeedEvent{
		{
			Uid:   liked,
			Type:  LikeEventName,
			Ctime: time.Now(),
			Ext:   ext,
		},
	})
}

func (f LikeEventService) FindHandleEvents(ctx context.Context, uid, timestamp, limit int64) ([]domain.FeedEvent, error) {
	return f.repo.FindPushEventListWithTyp(ctx, FollowEventName, uid, timestamp, limit)
}
